﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using FBGraph.ClientGenerator.CodeGen;

namespace FBGraph.ClientGenerator.Tests.CodeGen
{
    [TestClass]
    public class TypeReferenceTests
    {
        [TestMethod]
        public void InitializingWithSystemTypeSetsTypeProperty()
        {
            var type = new TypeReference(typeof(String));
            Assert.AreEqual(typeof(String), type.Type);
        }

        [TestMethod]
        public void InitializingWithGenericSystemTypeSetsTypeArguments()
        {
            var type = new TypeReference(typeof(List<String>));
            var expected = new TypeArgumentsList(new TypeReference(typeof(String)));
            var actual = type.TypeArguments;

            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void InitializaingWithGenericSystemTypeSetsMultipleTypeArguments()
        {
            var type = new TypeReference(typeof(Dictionary<String, Object>));
            var expected = new TypeArgumentsList(new TypeReference(typeof(String)), new TypeReference(typeof(Object)));
            var actual = type.TypeArguments;

            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void InitializingWithNestedGenericTypeSetsNestedTypeArguments()
        {
            var type = new TypeReference(typeof(List<List<String>>));
            var expected = new TypeArgumentsList(new TypeReference(typeof(List<String>)));
            var actual = type.TypeArguments;

            Assert.IsTrue(expected.SequenceEqual(actual));
        }

        [TestMethod]
        public void OutputFromType()
        {
            var type = new TypeReference(typeof(String));
            var expected = "String";
            var actual = type.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void OutputFromGenericType()
        {
            var type = new TypeReference(typeof(List<String>));
            var expected = "List<String>";
            var actual = type.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void OutputFromMultipleGenericType()
        {
            var type = new TypeReference(typeof(Dictionary<String, Object>));
            var expected = "Dictionary<String, Object>";
            var actual = type.ToString();

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void OutputFromNestedGenericType()
        {
            var type = new TypeReference(typeof(List<List<String>>));
            var expected = "List<List<String>>";
            var actual = type.ToString();

            Assert.AreEqual(expected, actual);
        }
    }
}